#!/usr/bin/python2

import sys
import random
import string

PID_MAX = 1000000000
LID_MAX = 1000000000
PNAME_LEN = 10
LNAME_LEN = 5

if len(sys.argv) < 5:
    print("Usage: gen_3_2.py #T1 #T2 tfile1 tfile2")
    exit(1)

num_tuple1 = int(sys.argv[1])
num_tuple2 = int(sys.argv[2])
output1 = sys.argv[3]
output2 = sys.argv[4]

if num_tuple1 >= PID_MAX:
    num_tuple1 = PID_MAX

if num_tuple2 >= LID_MAX:
    num_tuple2 = LID_MAX

print "Generating %d data items with %d foreign keys, write into %s & %s" % (num_tuple1, num_tuple2, output1, output2)

def ranstr(str_len):
    str_list = []
    for idx in range(0, str_len):
        str_list.append(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'))
    return string.join(str_list).replace(" ", "")

fd = open(output1, 'w')
for pid in range(0, num_tuple1):
    pname = ranstr(PNAME_LEN)
    lid = random.randrange(0, num_tuple2)
    fd.write("%9d\t%9d\t%s\n" % (pid, lid, pname))
fd.close()

fd = open(output2, 'w')
for lid in range(0, num_tuple2):
    lname = ranstr(LNAME_LEN)
    fd.write("%9d\t%s\n" % (lid, lname))
fd.close()
